//
//  GeoRefCustomCell.m
//  Tazama NGO
//
//  Created by jsheriff on 3/9/11.
//  Copyright 2011 The MITRE Corporation. All rights reserved.
//

#import "GeoRefCustomCell.h"

@implementation GeoRefCustomCell

@synthesize latitudeLabel;
@synthesize longitudeLabel;
@synthesize mapButton;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier mapButton:(BOOL)isVisible {
    if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier])) {
		// Initialization code
		latitudeLabel = [[UILabel alloc]init];
		latitudeLabel.textAlignment = UITextAlignmentLeft;
		latitudeLabel.font = [UIFont systemFontOfSize:16];
		
		longitudeLabel = [[UILabel alloc] init];
		longitudeLabel.textAlignment = UITextAlignmentLeft;
		longitudeLabel.font = [UIFont systemFontOfSize:16];
		
		[self.contentView addSubview:latitudeLabel];
		[self.contentView addSubview:longitudeLabel];

        mapButtonVisible = isVisible;
		if (mapButtonVisible) {
            mapButton = [UIButton buttonWithType:UIButtonTypeCustom];
            UIImage *img = [UIImage imageNamed:@"CurrentLoc.png"];
            [mapButton setImage:img forState:UIControlStateNormal];
            
            UIImage *buttonImageNormal = [UIImage imageNamed:@"whiteButton.png"];
            UIImage * stretchableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
            [mapButton setBackgroundImage:stretchableButtonImageNormal forState:UIControlStateNormal];
            
            UIImage *buttonImagePressed = [UIImage imageNamed:@"blueButton.png"];
            UIImage * stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
            [mapButton setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted];
            
            [self.contentView addSubview:mapButton];
        }
	}
	return self;
}

- (void)layoutSubviews {
	[super layoutSubviews];
	CGRect contentRect = self.contentView.bounds;
	CGFloat boundsX = contentRect.origin.x;
	CGRect frame;
	
	frame= CGRectMake(boundsX + 10, 15, 100, 16);
	latitudeLabel.frame = frame;
	
	frame= CGRectMake(boundsX + 110, 15, 120, 16);
	longitudeLabel.frame = frame;
	
    if (mapButtonVisible) {
        frame= CGRectMake(boundsX + 250, 7, 32, 32);
        mapButton.frame = frame;
    }
}

@end
